

public class longestStringWithoutRepeatingCharacters {
	
	public void tester()
	{
		String s = "a";
		for(int i = 0 ; false && i < 18 ;i ++)
			s=s+s;
		int result = lengthOfLongestSubstring(s);
		System.out.println(result);
	}
	
    public int lengthOfLongestSubstring(String s) {
        
        int max = 0, j = 0;
        
        int [] array = new int [127-32];
        
        /*if(j<s.length() && s.charAt(j) >= (char)32 && s.charAt(j) <= (char)126)
        	array[s.charAt(j)-32] ++;*/
        
        for(int i = 0 ; i < s.length() ; i ++)
        {
        	char c = s.charAt(i);
        	if(!(c >= (char)32 && c <= (char)126)) return 0;
            
        	array[c-32] ++;
        	if(array[c-32] > 1)
        	{
        		while(s.charAt(j) != c)
        		{
        			array[s.charAt(j)-32]--;
        			j++;
        		}
        		j++;
        		array[c-32]--;
        	}
        	
        	if(max < i-j+1) {
        		max = i-j+1;
//        		System.out.println(s.substring(j, i+1));
        	}
        }
        
        return max;
    }
}